<?php
namespace Home\Controller;
use Think\Controller;
class InterfaceMPController extends Controller {
    public function addUser(){//添加用户
        $uid=$_REQUEST['uid'];
        $username=I('request.username');
        $birthday=I('request.birthday');
        $sex=$_REQUEST['sex'];
        $addr=$_REQUEST['addr'];
        $remarks=$_REQUEST['remarks'];
        $longitude=$_REQUEST['longitude'];//经度
        $userData=$_REQUEST['user'];
        $del=$_REQUEST['del'];
        $type=$_REQUEST['type'];//1紫微命盘  2八字命盘  3住宅凶吉  4八字精批免费
        $imgUrl=$_REQUEST['imgUrl'];
        $x=$_REQUEST['x'];
        $y=$_REQUEST['y'];
        $deg=$_REQUEST['deg'];
        $scale=$_REQUEST['scale'];
        judgeData(array($uid,$username,$birthday),$_REQUEST);
        if(empty($del)){$del=1;}
        if(empty($type)){$type=1;}

        M()->query("insert into data_mingpan_user (uid,username,birthday,sex,addr,remarks,longitude,userData,del,type,houseImg,x,y,deg,scale)values('{$uid}','{$username}','{$birthday}','{$sex}','{$addr}','{$remarks}','{$longitude}','{$userData}','{$del}','{$type}','{$imgUrl}','{$x}','{$y}','{$deg}','{$scale}')");
        $sid=mysql_insert_id();
        $arr=array('code'=>1,'sid'=>$sid);
        echo json_encode($arr);
    }
    public function deleteUser(){//删除用户
        $sid=$_REQUEST['sid'];
        judgeData(array($sid),$_REQUEST);
        M()->query("delete from data_mingpan_user where sid='{$sid}'");
        $arr=array('code'=>1,);
        echo json_encode($arr);
    }
    public function updateUser(){//修改用户
        $sid=$_REQUEST['sid'];
        $username=I('request.username');
        $birthday=I('request.birthday');
        $sex=$_REQUEST['sex'];
        $imgUrl=$_REQUEST['imgUrl'];
        $x=$_REQUEST['x'];
        $y=$_REQUEST['y'];
        $deg=$_REQUEST['deg'];
        $scale=$_REQUEST['scale'];
        judgeData(array($username,$birthday,$sid),$_REQUEST);
        S('mingpan'.$sid,null);
        $updateStr="username='{$username}',birthday='{$birthday}'";
        if($sex||$sex==='0'){$updateStr.=",sex='{$sex}'";}
        if($imgUrl){$updateStr.=",houseImg='{$imgUrl}'";}
        if($x||$x==='0'){$updateStr.=",x='{$x}',y='{$y}',deg='{$deg}'";}
        if($scale||$scale==='0'){
            $updateStr.=",scale='{$scale}'";
        }

        M()->query("update data_mingpan_user set {$updateStr} where sid='{$sid}'");
        $arr=array('code'=>1,);
        echo json_encode($arr);
    }
    public function userData(){//查询用户数据
        $uid=$_REQUEST['uid'];
        $type=$_REQUEST['type'];
        judgeData(array($uid),$_REQUEST);
        if(empty($type)){
            $type=1;
        }
        $arr=M()->query("select * from data_mingpan_user where uid='{$uid}' and del<2 and type='{$type}' order by sid desc limit 15");
        foreach($arr as $key=>$value){
            $ymdArr=explode('-',$value['birthday']);
            $y=$ymdArr[1];
            $m=$ymdArr[2];
            $d=$ymdArr[3];
            $zyinli=yinli($y,$m,$d);
            $arr[$key]['yangli']=$y.'年'.$m.'月'.$d.'日';//阳历
            $arr[$key]['yinli']=$zyinli[0].'年'.$zyinli[1].$zyinli[2];//阴历
            $arr[$key]['shengxiao']=$zyinli[6];
        }

        $arr=array('code'=>1,'data'=>$arr);
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function sunTime(){//真太阳时
        $time=$_REQUEST['time'];
        $longitude=$_REQUEST['longitude'];//经度
        judgeData(array($time,$longitude),$_REQUEST);
        $Mingpan=new \Library\Mingpan();
        $date=$Mingpan->trueSunTime($time,$longitude);
        $arr=array(
            'code'=>1,
            'time'=>$date
        );
        echo json_encode($arr);
    }
    public function ZWmingpan($birthday=null,$sex=null,$lnYmdThis=null){//紫微命盘数据
        $sid=$_REQUEST['sid'];
        if(empty($sid)){$sid=1;}
        judgeData(array($sid),$_REQUEST);

        if($sid==3){
            cookie('typecs',1);
        }else{

        }

        $star=1;
        if($_REQUEST['birthday']){//其他业务使用接口
            $birthday=$_REQUEST['birthday'];
            $sex=$_REQUEST['sex'];
        }else if($birthday){//项目回调

        }else{//小程序使用
            if(S('mingpan'.$sid)){
                $userData=S('mingpan'.$sid);
            }else{
                $userData=M()->query("select username,birthday,sex,star,longitude from data_mingpan_user where sid='{$sid}'");
                S('mingpan'.$sid,$userData,30);
            }
            $birthday=$userData[0]['birthday'];
            $sex=$userData[0]['sex'];
            $star=$userData[0]['star'];
            $longitude=$userData[0]['longitude'];
        }


        $ymdArr=explode('-',$birthday);
        $str0=$ymdArr[0];
        if($str0>10){
            $day=substr($ymdArr[2],0,2);
            $hour=substr($ymdArr[2],3,2);
            $birthday="0-{$ymdArr[0]}-{$ymdArr[1]}-{$day}-".intval($hour);
        }

        $Mingpan=new \Library\Mingpan();
        $arr=S('ZWmingpan'.$birthday.$sex.$sid.$longitude);
        if(empty($arr)){
            $arr=$Mingpan->ziweidoushu($birthday,$sex,$star,$sid,$longitude,0,0,0,0,0,'MP');
            S('ZWmingpan'.$birthday.$sex.$sid.$longitude,$arr,3600);
        }


        //流年、流月、流日 盘
        $MingpanLn=new \Library\MingpanLn();
        if(empty($lnYmdThis)){//项目回调
            $lnYmd=date('Y-m-d',time());
        }else{
            $lnYmd=$lnYmdThis;
        }
        if($_REQUEST['lnymd']){
            $lnYmd=$_REQUEST['lnymd'];
        }

        $arrLn=S('liunian'.$lnYmd.$sex.$arr['zidou']);
        if(empty($arrLn)){
            $arrLn=$MingpanLn->liunian($lnYmd,$sex,$arr['zidou']);
            S('liunian'.$lnYmd.$sex.$arr['zidou'],$arrLn,3600);
        }


        //大运能量
        $yunshiLabel=$MingpanLn->labelYunshi($arr['data'],$arr['srg']);//运势标签
        $arr['dayunEnergy']['data'][0]['yunshiLabel']=$yunshiLabel;
        $srg=$arr['srg'];$sliceSrg=array_slice($srg,2,10);
        $srg=array_merge($srg,$sliceSrg);$srg=array_slice($srg,0,12);
        $yunshiLabel=$MingpanLn->labelYunshi($arr['data'],$srg);//运势标签
        $arr['dayunEnergy']['data'][1]['yunshiLabel']=$yunshiLabel;
        $sliceSrg=array_slice($srg,2,10);
        $srg=array_merge($srg,$sliceSrg);$srg=array_slice($srg,0,12);
        $yunshiLabel=$MingpanLn->labelYunshi($arr['data'],$srg);//运势标签
        $arr['dayunEnergy']['data'][2]['yunshiLabel']=$yunshiLabel;

        //流年数据
        $arrLnEveryY=$MingpanLn->LnEveryYear($arr['data'],$arrLn['lnShierg']);
        if($lnYmdThis){//项目回调
            return $arrLnEveryY;
        }
        //流月数据
        $arrLyEveryM=$MingpanLn->LyEveryMonth($arr['data'],$arrLn['lyShierg']);
        //流日数据
        $arrLrEveryD=$MingpanLn->LrEveryDay($arr['data'],$arrLn['lrShierg']);

        //今日星宿
        $arrTodayXx=$MingpanLn->TodayXxData($arr['data'],$arrLn['lrShierg'],$arrLn['sizhu']);

        //每月运势数据
        $arrLyYunshi=$MingpanLn->EveryDayData($birthday,$lnYmd,$arrLrEveryD,$arrLn['lyShierg'],$arr['data'],'month');
        //每日运势数据
        $arrLrYunshi=$MingpanLn->EveryDayData($birthday,$lnYmd,$arrLrEveryD,$arrLn['lrShierg'],$arr['data']);


        //大运十二宫
        //$arrDayunSrg=$MingpanLn->dayunSeg($arr['dayun']['gz'][0]);

        $arr['username']=$userData[0]['username'];
        $arr['birthday']=$userData[0]['birthday'];
        $arr['arrLnevery']=$arrLnEveryY;
        $arr['arrLyEvery']=$arrLyEveryM;
        $arr['arrLyYunshi']=$arrLyYunshi;
        $arr['arrLrEvery']=$arrLrEveryD;
        $arr['arrLrYunshi']=$arrLrYunshi;
        $arr['arrTodayXx']=$arrTodayXx;

        //dump($arr);exit;

        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function ZWanalysis(){//紫微命盘解析
        $sid=$_REQUEST['sid'];
        judgeData(array($sid),$_REQUEST);
        if(S('mingpan'.$sid)){
            $userData=S('mingpan'.$sid);
        }else{
            $userData=M()->query("select username,birthday,sex,star,longitude from data_mingpan_user where sid='{$sid}'");
            S('mingpan'.$sid,$userData,30);
        }
        $birthday=$userData[0]['birthday'];
        $sex=$userData[0]['sex'];
        $Mingpan=new \Library\Mingpan();
        $arr=$Mingpan->ZWanalysis($birthday,$sex);

        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function ZWeveryProblem(){//紫微每日简答
        if($_REQUEST['birthday']){
            $birthday=$_REQUEST['birthday'];
            $sex=$_REQUEST['sex'];
            $subject=$_REQUEST['subject'];
            $type=$_REQUEST['type'];
        }
        judgeData(array($birthday,$subject),$_REQUEST);

        $ymdArr=explode('-',$birthday);
        $str0=$ymdArr[0];
        if($str0>10){
            $day=substr($ymdArr[2],0,2);
            $hour=substr($ymdArr[2],3,2);
            $birthday="0-{$ymdArr[0]}-{$ymdArr[1]}-{$day}-".intval($hour);
        }
        $Mingpan=new \Library\Mingpan();
        $arr=$Mingpan->ziweidoushu($birthday,$sex);

        //流年、流月、流日 盘
        $MingpanLn=new \Library\MingpanLn();
        $lnYmd=date('Y-m-d',time());
        if($_REQUEST['lnymd']){
            $lnYmd=$_REQUEST['lnymd'];
        }
        $arrLn=$MingpanLn->liunian($lnYmd,$sex,$arr['zidou']);

        if($type=='day'){//流日
            $arr=$MingpanLn->LrEveryProblem($arr['data'],$arrLn['lrShierg'],$subject);
        }else{   //流月
            $arr=$MingpanLn->LrEveryProblem($arr['data'],$arrLn['lyShierg'],$subject);
        }

        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function BZmingpan(){//八字命盘
        $sid=$_REQUEST['sid'];
        judgeData(array($sid),$_REQUEST);
        if(S('mingpan'.$sid)){
            $userData=S('mingpan'.$sid);
        }else{
            $userData=M()->query("select username,birthday,sex,star,longitude,addr from data_mingpan_user where sid='{$sid}'");
            S('mingpan'.$sid,$userData,10);
        }
        $birthday=$userData[0]['birthday'];
        $sex=$userData[0]['sex'];
        $longitude=$userData[0]['longitude'];
        $Mingpan=new \Library\Mingpan();
        $arr=$Mingpan->bazipaipan($birthday,$sex,$longitude);
        $arr['username']=$userData[0]['username'];
        $arr['birthday']=$userData[0]['birthday'];
        $arr['addr']=$userData[0]['addr'];
        //dump($arr); exit;

        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }

    public function getOpenid(){//小程序获取openid
        $code=$_REQUEST['code'];
        $type=$_REQUEST['type'];
        if($type==2){//小程紫微排盘
            $url = "https://api.weixin.qq.com/sns/jscode2session?appid=wx73ded2733c362248&secret=519ce8418e73e266c8de235378c1d524&js_code={$code}&grant_type=authorization_code";
        }else if($type==3){//住宅
            $url = "https://api.weixin.qq.com/sns/jscode2session?appid=wxa08acaa21c6c7a5e&secret=8e1e740a5b88cf3ab385c4fef86ca47e&js_code={$code}&grant_type=authorization_code";
        }else if($type==4){//免费八字精批
            $url = "https://api.weixin.qq.com/sns/jscode2session?appid=wx111fd5ecc0b08287&secret=eec2b18c4f2b9e2c94072efaaf3bbafa&js_code={$code}&grant_type=authorization_code";
        } else{
            $url = "https://api.weixin.qq.com/sns/jscode2session?appid=wxbb86bd400ca5108b&secret=5f6b5374b7eed8f59a782cc7773e4bd4&js_code={$code}&grant_type=authorization_code";//八字
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);//设置请求地址
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//不需要证书验证
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//不需要主机验证
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $json = curl_exec($ch);
        echo $json;
    }

    public function followWx(){//关注公众号信息
        $arr=array(
            'text'=>'在微信公众号中搜索“知命”或扫描下方二维码关注',
            'wechatNum'=>'dashisuanming',
            'img'=>'https://hy.yixueqm.com/zhiming/Public/images/public/qrcode_for_gh.jpg',
        );
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }

    function houseJiliPosition(){//住宅吉利方位
        $sid=$_REQUEST['sid'];
        judgeData(array($sid),$_REQUEST);
        if(S('mingpan'.$sid)){
            $userData=S('mingpan'.$sid);
        }else{
            $userData=M()->query("select username,birthday,sex,star,longitude,houseImg,x,y,deg,scale from data_mingpan_user where sid='{$sid}'");
            S('mingpan'.$sid,$userData,30);
        }
        $birthday=$userData[0]['birthday'];
        $sex=$userData[0]['sex'];
        $ymdArr=explode('-',$birthday);
        $y=$ymdArr[1];
        $m=$ymdArr[2];
        $d=$ymdArr[3];
        $hour=intval($ymdArr[4]);
        $ymd=$y.'-'.str_pad($m,2,"0",STR_PAD_LEFT).'-'.str_pad($d,2,"0",STR_PAD_LEFT);

        if($sex==1){$zsex='男';
        }else{$zsex='女';}
        if($ymd!=''){
            zwmp($ymd,$hour,$zsex,'zw');
            $arrzx=I('globals.arrzx');$arrtf=I('globals.arrtf');
            $syzx=I('globals.syzx');$sxzx=I('globals.sxzx');
            $sngx=I('globals.sngx');$snzx=I('globals.snzx');
            $qtx=I('globals.qtx');
        }
        $dizhiGW=array(0=>'寅',1=>'卯',2=>'辰',3=>'巳',4=>'午',5=>'未',6=>'申',7=>'酉',8=>'戌',9=>'亥',10=>'子',11=>'丑');
        $ziweiArr=array(
            '天梁'=>'磨难位', '贪狼'=>'欲望位', '阴煞'=>'小人位', '红鸾'=>'桃花位', '天喜'=>'喜神位', '文昌'=>'文昌位', '紫微'=>'命宫位', '铃星'=>'警惕位', '天同'=>'福星位',
            '天魁'=>'贵人位', '火星'=>'火爆位', '擎羊'=>'伤害位', '破军'=>'动荡位', '地劫'=>'破失位', '禄存'=>'财位', '太阳'=>'声名位', '地空'=>'空虚位', '巨门'=>'是非位',
        );
        $positionXjArr=array(
            '磨难位'=>'凶', '欲望位'=>'吉', '小人位'=>'凶', '桃花位'=>'吉', '喜神位'=>'吉', '文昌位'=>'吉', '命宫位'=>'吉', '警惕位'=>'凶', '福星位'=>'吉',
            '贵人位'=>'吉', '火爆位'=>'凶', '伤害位'=>'凶', '动荡位'=>'凶', '破失位'=>'凶', '财位'=>'吉', '声名位'=>'吉', '空虚位'=>'凶', '是非位'=>'凶',
        );

        foreach($dizhiGW as $key=>$value){
            $dzWZ=$key;
            $arrData=array(
                mb_substr($arrzx[$dzWZ],0,2,'utf-8'), mb_substr($arrtf[$dzWZ],0,2,'utf-8'), mb_substr($sxzx[$dzWZ],0,2,'utf-8'), mb_substr($sxzx[$dzWZ],3,2,'utf-8'), mb_substr($sngx[$dzWZ],0,2,'utf-8'), mb_substr($sngx[$dzWZ],3,2,'utf-8'), mb_substr($syzx[$dzWZ],0,2,'utf-8'),
                mb_substr($syzx[$dzWZ],3,2,'utf-8'), mb_substr($snzx[$dzWZ],0,2,'utf-8'), mb_substr($snzx[$dzWZ],3,2,'utf-8'), mb_substr($qtx[$dzWZ],0,2,'utf-8'), mb_substr($qtx[$dzWZ],3,2,'utf-8'), mb_substr($qtx[$dzWZ],6,2,'utf-8'),
            );
            $arrData=array_filter($arrData);
            $arrGW=array();
            foreach($arrData as $kX=>$vY){
                if($ziweiArr[$vY]){
                    array_push($arrGW,$ziweiArr[$vY]);
                }
            }

            $arrGWArr=array();
            foreach($arrGW as $k=>$v){
                $arrGWArr[$k]['name']=$v;
                if($positionXjArr[$v]=='吉'){
                    $arrGWArr[$k]['xj']='吉';
                    $arrGWArr[$k]['color']='#FF0000';
                }else{
                    $arrGWArr[$k]['xj']='凶';
                    $arrGWArr[$k]['color']='#080808';
                }
            }

            $arr[$key]['data']=$arrGWArr;
        }

        foreach($arr as $key=>$value){
            $arr[$key]['dizhi']=$dizhiGW[$key];
        }
        foreach($arr as $key=>$value){
            $ArrData[$key+1]=$value;
        }
        $ArrData['userData']=$userData[0];

        //dump($ArrData);
        echo json_encode($ArrData,JSON_UNESCAPED_UNICODE);
    }
    public function houseJiliExplain(){//住宅吉利解释
        $data=json_decode($_REQUEST['data']);//["磨难位","贵人位"]
        judgeData(array($data),$_REQUEST);

        $dataClass=new \Library\Data();
        foreach($data as $key=>$value){
            $houseData=$dataClass->houseJiliData($value);
            $arr[$key]=$houseData;
        }
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function houseJiliJgfx(){//九宫飞星位置
        $dataClass=new \Library\Data();
        $houseData=$dataClass->houseJiliJgfx(10);
        echo json_encode($houseData,JSON_UNESCAPED_UNICODE);
    }
    public function houseJiliJgfxData(){//九宫飞星解释
        $number=json_decode($_REQUEST['number']);
        judgeData(array( $number),$_REQUEST);
        $dataClass=new \Library\Data();
        $houseData=$dataClass->houseJiliJgfx($number);
        echo json_encode($houseData,JSON_UNESCAPED_UNICODE);
    }
    public function morePaipan(){//更多排盘
        $type=$_REQUEST['type'];
        $dataArr=array(
            1=>array(
                'name'=>'紫微排盘',
                'img'=>'https://hy.yixueqm.com/zhiming/Public/images/public/mianxiang@2x.png',
                'text'=>'提供高精度万年历，让可排盘的时间范围大，使原本复杂的排盘变的容易。',
                'url'=>'url',
                'appid'=>'wxbb86bd400ca5108b',
                'path'=>'pages/edit/main',
            ),
            2=>array(
                'name'=>'八字排盘',
                'img'=>'https://hy.yixueqm.com/zhiming/Public/images/public/bazipaipan@2x.png',
                'text'=>'提供给命理爱好者学习、研究和使用，依据出生日期等资料，推算出八字命盘数据。',
                'url'=>'url',
                'appid'=>'wx73ded2733c362248',
                'path'=>'pages/edit/main',
            ),
            3=>array(
                'name'=>'住宅吉凶',
                'img'=>'https://hy.yixueqm.com/zhiming/Public/images/public/huxingfengshui@2x.png',
                'text'=>'知道你家中的财位、文昌、桃花等几十种吉凶方位，让你不用再找风水师花钱看风水。',
                'url'=>'url',
                'appid'=>'wxa08acaa21c6c7a5e',
                'path'=>'pages/edit/main',
            ),
//            4=>array(
//                'name'=>'八字精批',
//                'img'=>'https://hy.yixueqm.com/zhiming/Public/images/public/bazijingpi@2x.png',
//                'text'=>'专业命盘精论流年运势，一次掌握一年中整体、桃花婚姻、财运工作、健康家庭等运势的吉凶变化。',
//                'url'=>'url',
//                'appid'=>'wx111fd5ecc0b08287',
//                'path'=>'pages/edit/main',
//            ),
        );
        foreach($dataArr as $key=>$value){
            if($key==$type){
            }else{
                $arr[$key]=$dataArr[$key];
            }
        }
        $arr=array_values($arr);
        foreach($arr as $key=>$value){
            $Arr[$key+1]=$value;
        }
        echo json_encode($Arr,JSON_UNESCAPED_UNICODE);
    }
    public function updateImg($file=null){//图片上传
        if($_FILES['file']){
            $file=$_FILES['file'];
        }
        file_put_contents("./Upload/updateImgData.txt",json_encode($_REQUEST));

        if(is_uploaded_file($file['tmp_name'])) {
            $uploaded_file=$file['tmp_name'];
            //我们给每个用户动态的创建一个文件夹
            $user_path=mb_substr(THINK_PATH,0,-9).'Upload/house/'.date("Y-m");
            //判断该用户文件夹是否已经有这个文件夹  
            if(!file_exists($user_path)) {
                //mkdir($user_path); 
                mkdir($user_path,0777,true);
            }

            //$move_to_file=$user_path."/".$file['file']['name'];  
            $file_true_name=$file['name'];
            $randNum="/".date("Ymd").'-'.time().'-'.rand(1,1000).substr($file_true_name,strrpos($file_true_name,"."));
            $move_to_file=$user_path.$randNum;//strrops($file_true,".")查找“.”在字符串中最后一次出现的位置
            $imageadd="https://hy.yixueqm.com/zhiming/Upload/house/".date("Y-m").$randNum;
            //echo "$uploaded_file   $move_to_file";
            if(move_uploaded_file($uploaded_file,$move_to_file)) {
                $arr=array(
                    'code'=>1,
                    'text'=>'成功',
                    'imgUrl'=>$imageadd
                );
                echo json_encode($arr,JSON_UNESCAPED_UNICODE);
            } else {
                $arr=array(
                    'code'=>0,
                    'text'=>'上传失败',
                );
                echo json_encode($arr,JSON_UNESCAPED_UNICODE);
            }
        } else {
            $arr=array(
                'code'=>0,
                'text'=>'上传失败',
            );
            echo json_encode($arr,JSON_UNESCAPED_UNICODE);
        }
    }

    public function bzjpFreeData(){//八字精批免费数据
        $sid=$_REQUEST['sid'];
        judgeData(array($sid),$_REQUEST);
        if(S('mingpan'.$sid)){
            $userData=S('mingpan'.$sid);
        }else{
            $userData=M()->query("select sid,uid,username,birthday,sex from data_mingpan_user where sid='{$sid}'");
            S('mingpan'.$sid,$userData,30);
        }
        $birthday=$userData[0]['birthday'];
        $sex=$userData[0]['sex'];
        $ymdArr=explode('-',$birthday);
        $y=$ymdArr[1];
        $m=$ymdArr[2];
        $d=$ymdArr[3];
        $hour=$ymdArr[4];
        $zymd=$y.'-'.str_pad($m,2,"0",STR_PAD_LEFT).'-'.str_pad($d,2,"0",STR_PAD_LEFT);

        if($sex==1){$zsex='男';
        }else{$zsex='女';}

        zwmp($zymd,$hour,$zsex,'zw');
        $ssarray=array();
        array_push($ssarray,implode(I('globals.nianzhuss')));
        array_push($ssarray,implode(I('globals.yuezhuss')));
        array_push($ssarray,implode(I('globals.shizhuss')));
        $shengxiao=I('globals.shengxiao');
        $dayun=I('globals.dayun');//大运
        $dayunx=I('globals.dayunx');//大运x
        $dayuny=I('globals.dayuny');//大运y
        liunian(I('globals.bznianzhu'));
        fortune(I('globals.shengxiao'),I('globals.bzrizhu'));
        $liunian=I('globals.liunian');
        wuxing_healthy(mb_substr($liunian['ny'],2,1,'utf-8'));
        $wuxing=I('globals.wuxing');
        wuxing_healthy(I('globals.xiys'));

        $zhanxing=new \Library\ZhanXing();
        $constellation=$zhanxing->constellation($m,$d);//获取星座
        $cArr2019=yunshi2019($constellation);//2019运势


        //紫薇
        cyzk(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'),I('globals.shua'));
        $cyzkzx=I('globals.cyzkzx');//财运主星
        syfz(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'),I('globals.shua'));
        $syfzzx=I('globals.syfzzx');//事业主星
        hyqg(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'),I('globals.shua'));
        $hyqgzx=I('globals.hyqgzx');//婚姻主星
        zsqk(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'));
        $zsqkzx=I('globals.zsqkzx');//自身主星

        $ziweiFenxi=BZziweiFenxi($syfzzx,$cyzkzx,$hyqgzx,$zsqkzx);


        $zyinli=yinli($y,$m,$d);
        cookie('yangli',$y.'年'.$m.'月'.$d.'日'.' '.$hour.'时',604800);//阳历
        cookie('yinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2],604800);//阴历

        //大运
        $dayun=array(
            'name'=>"出生后{$dayunx}年{$dayuny}月起大运",
            'gz'=>I('globals.dayungz'),
            'age'=>array($dayun,$dayun+10,$dayun+20,$dayun+30,$dayun+40,$dayun+50,$dayun+60,$dayun+70,$dayun+80),
        );

        //商品文案
        $shopClerk_yskb4=S('shopClerk_yskb4Xcx'.$shengxiao);
        if(empty($shopClerk_yskb4)){
            $shopClerk4=M()->query("select brief,img,url from shop_clerk where name='yskb' and shopName='kaiyun4' and  typeName='{$shengxiao}'");
            $shopClerk_yskb=$shopClerk4[0];S('shopClerk_yskb4Xcx'.$shengxiao,$shopClerk_yskb4,600);
        }

        $shopClerk_gqsh1=S('shopClerk_gqsh1Xcx');
        if(empty($shopClerk_gqsh1)){
            $shopClerk1=M()->query("select brief,img,url from shop_clerk where name='gqsh' and shopName='kaiyun1' and  typeName='50'");
            $shopClerk_gqsh=$shopClerk1[0];S('shopClerk_gqsh1Xcx',$shopClerk_gqsh1,600);
        }

        $shopClerk_cy1=S('shopClerk_cy1Xcx');
        if(empty($shopClerk_cy1)){
            $shopClerk1=M()->query("select brief,img,url from shop_clerk where name='cy' and shopName='kaiyun1'");
            $shopClerk_cy=$shopClerk1[0];S('shopClerk_cy1Xcx',$shopClerk_cy1,600);
        }

        $shopClerk_sy1=S('shopClerk_sy1Xcx');
        if(empty($shopClerk_sy1)){
            $shopClerk1=M()->query("select brief,img,url from shop_clerk where name='sy' and shopName='kaiyun1'");
            $shopClerk_sy=$shopClerk1[0];S('shopClerk_sy1Xcx',$shopClerk_sy1,600);
        }

        $shopClerk_jk1=S('shopClerk_jk1Xcx');
        if(empty($shopClerk_jk1)){
            $shopClerk1=M()->query("select brief,img,url from shop_clerk where name='jk' and shopName='kaiyun1'");
            $shopClerk_jk=$shopClerk1[0];S('shopClerk_jk1Xcx',$shopClerk_jk1,600);
        }

        $shopClerk_xxys1=S('shopClerk_xxys1Xcx');
        if(empty($shopClerk_xxys1)){
            $shopClerk1=M()->query("select brief,img,url from shop_clerk where name='xxys' and shopName='kaiyun1'");
            $shopClerk_xxys=$shopClerk1[0];S('shopClerk_xxys1Xcx',$shopClerk_xxys1,600);
        }
        $shopArr=array(
            'shopClerk_yskb'=>$shopClerk_yskb,
            'shopClerk_gqsh'=>$shopClerk_gqsh,
            'shopClerk_cy'=>$shopClerk_cy,
            'shopClerk_sy'=>$shopClerk_sy,
            'shopClerk_jk'=>$shopClerk_jk,
            'shopClerk_xxys'=>$shopClerk_xxys,
        );

        $selectArr=array(
            'yangli'=>cookie('yangli'),
            'yinli'=>cookie('yinli'),
            'sizhu'=>I('globals.sizhu'),
            'nianzhuss'=>$ssarray,
            'canggan'=>I('globals.canggan'),
            'zhishen'=>I('globals.zhishen'),
            'sizhuny'=>I('globals.sizhuny'),
            'bzdishi'=>I('globals.bzdishi'),
            'wxsqs'=>I('globals.wxsqs'),
            'xiys'=>I('globals.xiys'),
            'taiyuan'=>I('globals.taiyuan'),
            'rikong'=>I('globals.rikong'),
            'dayun'=>$dayun,

            'liunian'=>I('globals.liunian'),
            'shortcoming'=>I('globals.shortcoming'),
            'fortune'=>I('globals.fortune'),
            'congenital'=>I('globals.congenital'),
            'becareful'=>I('globals.be_careful'),
            'lovefenxi'=>I('globals.lovefenxi'),
            'arrtaohua'=>I('globals.arrtaohua'),
            'shengxiaosh'=>I('globals.shengxiaosh'),
            'wuxing'=>$wuxing,
            'cause'=>I('globals.wuxing'),
            'ziweidoushu'=>$ziweiFenxi,
            'liuyue2019'=>$cArr2019,
            'shopArr'=>$shopArr,
            'userData'=>$userData,
        );
        echo json_encode($selectArr,JSON_UNESCAPED_UNICODE);
    }

    public function Qizhengsiyu(){//七政四余
        $birthday=$_REQUEST['birthday'];
        $sex=$_REQUEST['sex'];
        judgeData(array($birthday,$sex),$_REQUEST);
        if($_REQUEST['lnymd']){
            $lnYmd=$_REQUEST['lnymd'];//流年日期
        }
        $qizhengsiyu=new \Library\Qizhengsiyu();
        $qzsyArr=$qizhengsiyu->index($birthday,$sex,$lnYmd);
        //dump($qzsyArr);

        //$JGdata=$qizhengsiyu->DataTotal($qzsyArr['sizhu'],$qzsyArr['gongwei']);

        echo json_encode($qzsyArr,JSON_UNESCAPED_UNICODE);
    }
    public function sidGet(){//sid数据获取接口
        $sid=$_REQUEST['sid'];
        judgeData(array($sid),$_REQUEST);
        if(S('mingpan'.$sid)){
            $userData=S('mingpan'.$sid);
        }else{
            $userData=M()->query("select username,birthday,sex,star,longitude,addr from data_mingpan_user where sid='{$sid}'");
            S('mingpan'.$sid,$userData,30);
        }
        echo json_encode($userData,JSON_UNESCAPED_UNICODE);
    }
}